package jinyilw.swing.visuals.panel;

import java.awt.Point;

public class Position
{
	private final PositionProducer producer;
	private int row;
	private int col;
	private int x, y;
	private boolean used;
	private Object data;

	public Position(PositionProducer p)
	{
		producer = p;
	}

	public Position(PositionProducer p, int ro, int co)
	{
		producer = p;
		setPosition(ro, co);
	}

	public void setPosition(int ro, int co)
	{
		row = ro;
		col = co;
		update();
	}

	public Position decrementCol()
	{
		col = col - 1;
		x = x - producer.W - producer.S;
		return this;
	}

	public Position change(int xx, int yy)
	{
		x = x + xx;
		y = y + yy;
		return this;
	}

	public Position update()
	{
		x = (producer.W + producer.S) * col + producer.leftB;
		y = (producer.H + producer.S) * row + producer.upB;
		return this;
	}

	public int getRow()
	{
		return row;
	}

	public int getCol()
	{
		return col;
	}

	public Point getPoint()
	{
		return new Point(x, y);
	}

	public int getX()
	{
		return x;
	}

	public int getY()
	{
		return y;
	}

	public int getW()
	{
		return producer.W;
	}

	public int getH()
	{
		return producer.H;
	}

	public void setX(int x)
	{
		this.x = x;
	}

	public void setY(int y)
	{
		this.y = y;
	}

	public int getIndex(int x, int y)
	{
		return producer.getIndex(x, y);
	}

	public boolean isUsed()
	{
		return used;
	}

	public void setUsed(boolean used)
	{
		this.used = used;
	}

	public Object getData()
	{
		return data;
	}

	public void setData(Object data)
	{
		this.data = data;
	}
}
